//index.js
//获取应用实例
var app = getApp()
Page({
	data: {
		root:'',
		siteroot:app.setting.siteroot,
		att_url:app.setting.att_url,
		account:app.setting.account,
		pagetitle:'获得购物卡' + '-' + app.setting.title,
		
	},
	onReady: function (){
	},
	onPullDownRefresh: function (){
		var the=this;
		var opt={};
		the.onLoad(opt);
		setTimeout(function(){
			wx.stopPullDownRefresh()
		},1000);
	},
	onLoad: function (){
		var page=this;
		wx.setNavigationBarTitle({'title':page.data.pagetitle});
		app.util.get(app.access,function(pagedata){
			console.log('getcard');console.log(pagedata);
			page.setData({
				pagedata:pagedata
			});
		});
	},
	getcard:function(e){
		var data=e.currentTarget.dataset;
		app.util.post('jy_weishop/member.getcard/getcard/',data);
	},
	//提交订单
	pay_credit:function(e){
		var page=this
		var data=e.currentTarget.dataset;
		app.util.pay_credit(data.id,function(res){
				page.setData({
						showpaymodal:false,
				});
				if(res.type=='success'){
					app.util.msg(res.message,'','jy_weishop/member.mycard/');
				}else{
					app.util.msg(res.message,'','jy_weishop/member.mycard/');
				}
		})
	},
	pay_wechat:function(e){
		var page=this
		var data=e.currentTarget.dataset;
		app.util.pay_wechat(data.id,function(res){
				page.setData({
						showpaymodal:false,
				});
				if(res.type=='success'){
					app.util.msg(res.message,'','jy_weishop/member.mycard/');
				}else{
					app.util.msg(res.message,'','jy_weishop/member.mycard/');
				}
		})
	},
	pay_alipay:function(e){
		var page=this
		var data=e.currentTarget.dataset;
		app.util.pay_alipay(data.id,function(res){
				page.setData({
						showpaymodal:false,
				});
				if(res.type=='success'){
					app.util.msg(res.message,'','jy_weishop/member.mycard/');
				}else{
					app.util.msg(res.message,'','jy_weishop/member.mycard/');
				}
		})
	},
	pay_hdfk:function(e){
		var page=this
		var data=e.currentTarget.dataset;
		app.util.pay_hdfk(data.id,function(res){
				page.setData({
						showpaymodal:false,
				});
				if(res.type=='success'){
					app.util.msg(res.message,'','jy_weishop/member.mycard/');
				}else{
					app.util.msg(res.message,'','jy_weishop/member.mycard/');
				}
		})
	},
	buy:function(e){
		var page=this
		var data=e.currentTarget.dataset;
		app.util.post('jy_weishop/member.getcard/buy/',{'id':data.id},function(payid){
			app.util.pay(payid,function(res){		
				if(res.type=='more'){
					page.setData({
						showpaymodal:true,
						'pagedata.paymodal':res
					});
				}else if(res.type=='success'){
					app.util.msg(res.message,'','jy_weishop/member.mycard/');
				}else{
					app.util.msg(res.message);
				}
			});
		});
	},
  	click:function(evt){
		//用户点击事件 data.func 为方法名，data.params 为调用参数！
		var data=evt.currentTarget.dataset;
		app.util[data.func](data.params);
	},
});